from django.db import models
from utils.basemodel import BaseModel

# Create your models here.
class UserProfile(BaseModel):
    """用户表"""
    username = models.CharField(max_length=11,verbose_name='用户名',unique=True)
    password = models.CharField(max_length=32)
    email = models.EmailField()
    phone = models.CharField(max_length=11)
    is_active = models.BooleanField(default=False,verbose_name='是否激活')

    #修改表名
    class Meta:
        #表名：应用名_类名非驼峰
        db_table = 'user_user_profile'


class Address(BaseModel):
    """
    收货地址表
    用户表：地址表 --> 1:n
    """
    user_profile = models.ForeignKey(UserProfile,on_delete=models.CASCADE)
    #收件人 地址 邮箱 手机号
    receiver = models.CharField(verbose_name="收件人",max_length=10)
    address = models.CharField(verbose_name="收件地址",max_length=200)
    postcode = models.CharField(verbose_name="邮编",max_length=6)
    receiver_mobile = models.CharField(verbose_name="手机号",max_length=11)
    #标签 默认地址
    tag = models.CharField(verbose_name="标签",max_length=10)
    is_default = models.BooleanField(verbose_name="默认地址",default=False)
    #伪删除
    is_active = models.BooleanField(verbose_name="是否删除",default=True)

    # 修改表名
    class Meta:
        # 表名：应用名_类名非驼峰
        db_table = 'user_address'


class WeiboProfile(BaseModel):
    """
    微博表
    微博表：用户表--->1:1
    """
    #微博扫码登录时，暂且不知道和哪个用户 绑定
    #用户输入完成用户信息后，再更新外键的值即可
    user_profile = models.OneToOneField(UserProfile,on_delete=models.CASCADE,null=True)
    wuid = models.CharField(verbose_name="微博uid",max_length=20,db_index=True,unique=True)
    access_token = models.CharField(verbose_name="授权令牌",max_length=32)

    class Meta:
        db_table = "user_weibo_profile"



